package com.tinyseed.emcp.api.basicdata.model;

import com.tinyseed.emcp.api.basicdata.domain.Enterprise;
import com.tinyseed.emcp.api.basicdata.domain.Monitor;
import com.tinyseed.emcp.api.basicdata.domain.Workshop;
import com.tinyseed.emcp.api.basicdata.domain.convert.DTOConvert;
import com.tinyseed.hmxx.common.annotation.Query;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.sql.Timestamp;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MonitorInputDTO implements Serializable {

    private Long id;
    /**
     * 监测点名称
     */
    @Query(type = Query.Type.RIGHT_LIKE)
    private String monitorName;
    /**
     * 网关编号
     */
    private String switchSn;
    /**
     * 功率启停阈值(kW)
     */
    private Double powerLimit;
    /**
     * 功率门限时间(分钟)
     */
    private Long powerTime;
    /**
     * 车间id
     */
    private Long shopId;
    /**
     * 电压变比(电压互感器)
     */
    private String pt;
    /**
     * 电流变比(电流互感器)
     */
    private String ct;
    /**
     * 备注
     */
    private String remark;
    /**
     * 最后修改时间
     */
    private Timestamp modifyTime;
    /**
     * 创建时间
     */
    private Timestamp createTime;
    /**
     * 创建人
     */
    private String creator;
    /**
     * 最后操作人
     */
    private String modifier;
    /**
     * 监测点编码
     */
    private String monitorCode;
    /**
     * 设备类型
     */
    private String equipmentType;
    /**
     * 仪表地址
     */
    private String instrumentAddress;
    /**
     * 仪表型号
     */
    private String instrumentModel;
    /**
     * 额定功率(kw)
     */
    private Double ratedPower;
    /**
     * 额定电压(V)
     */
    private Double ratedVoltage;

    @Query(propName = "createTime", type = Query.Type.GREATER_THAN)
    private String createTimeStart;

    @Query(propName = "createTime", type = Query.Type.LESS_THAN)
    private String createTimeEnd;

    private String enterpriseName;

    public Monitor convertToMonitor() {
        MonitorInputDTO.MonitorInputDTOConvert convert = new MonitorInputDTO.MonitorInputDTOConvert();
        Monitor result = convert.convert(this);
        return result;
    }

    private static class MonitorInputDTOConvert implements DTOConvert<MonitorInputDTO, Monitor> {

        @Override
        public Monitor convert(MonitorInputDTO monitorInputDTO) {
            Monitor monitor = new Monitor();
            BeanUtils.copyProperties(monitorInputDTO, monitor);
            return monitor;
        }
    }

}
